package com.qianfeng.freeshiro.controller;

//import com.qianfeng.freeshiro.util.MyException;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.servlet.ModelAndView;
//
//@ControllerAdvice
//public class DoExceptionController {
//    @ExceptionHandler
//    public ModelAndView doException(Exception e){
//        if(e instanceof MyException){
//            MyException ex = (MyException)e;
//            if(ex.getMessage().equals("E1001")){
//                ModelAndView mv = new ModelAndView("/login");
//                mv.addObject("msg", "用户名或密码错误");
//                return mv;
//            }else {
//                ModelAnds i 要View mv = new ModelAndView("/error");
//                return mv;
//            }
//        }else{
//            ModelAndView mv = new ModelAndView("/error");
//            return mv;
//        }
//    }
//}
@ControllerAdvice
public class DoExceptionController {

    @ExceptionHandler( { UnauthorizedException.class })
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public ModelAndView processUnauthorizedException(
            NativeWebRequest request, UnauthorizedException e) {
        ModelAndView mv = new ModelAndView("/403");
//        mv.addObject(contextPath, request.getContextPath());
//        mv.addObject(exception, e);
//        mv.setViewName(special/unauthorized);
        return mv;
    }
}